<template>
  <div class="video">
    <van-list
      v-model:loading="state.loading"
      :finished="state.finished"
      finished-text="没有更多了"
      @load="onLoad"
    >
      <ul>
        <!-- //渲染页面数据 -->
        <li class="video-frame" v-for="item in state.list" :key="item.id">
          <div class="video-frame-top">
            <div class="video-frame-top-left">
              <img :src="require('@/assets/images/log30.png')" alt="" />
            </div>
            <div class="video-frame-top-center">
              <div class="video-frame-top-center-top">轻语</div>
              <div class="video-frame-top-center-bottom">
                <span class="span-1">06-16</span>·<span class="span-2"
                  >机动战姬：聚变</span
                >
              </div>
            </div>
            <div class="video-frame-top-right">关注</div>
          </div>
          <router-link :to="'/details/' + item.id">
            <div class="video-frame-center">
              <div class="video-frame-center-top">{{ item.title }}</div>
              <div class="video-frame-center-bottom">
                <img :src="item.Imgurl" alt="" />
              </div>
            </div>
          </router-link>
          <div class="video-frame-bottom">
            <div class="video-frame-bottom-left">
              <span class="span_1">
                <img :src="require('@/assets/images/transmit.png')" alt="" />
              </span>
              <span class="span_2">84</span>
              <span class="span_1">
                <img :src="require('@/assets/images/comment.png')" alt="" />
              </span>
              <span class="span_2">1571</span>
              <span class="span_1">
                <img :src="require('@/assets/images/give.png')" alt="" />
              </span>
              <span class="span_2">4148</span>
            </div>
            <div class="video-frame-bottom-right">:</div>
          </div>
        </li>
      </ul>
    </van-list>
  </div>
</template>

<script>
//引入插件
import { reactive } from "vue";
import { getmoreApi } from "@/utils/api.js";

export default {
  setup() {
    //保存数据
    const state = reactive({
      list: [],
      loading: false,
      finished: false,
    });
    //设置页面下拉加载
    let pageSize = 2;
    let currentPage = 1;
    const onLoad = async () => {
      const res = await getmoreApi({
        pageSize,
        currentPage,
      });
      state.list.push(...res.result);
      currentPage++;

      state.loading = false;

      if (state.list.length >= res.count) {
        state.finished = true;
      }
    };
    //导出数据
    return {
      state,
      onLoad,
    };
  },
};
</script>

<style scoped>
.video {
  position: fixed;
  left: 0;
  right: 0;
  top: 60px;
  z-index: -1;
  bottom: 57px;
  overflow-y: scroll;
  padding: 0 16px;
}
.video-frame {
  width: 343px;
  margin-top: 15px;
  border-bottom: 1px solid #e1e1e1;
}
.video-frame-top {
  width: 100%;
  height: 42px;
  display: flex;
  justify-content: space-between;
}
.video-frame-top-left {
  width: 42px;
  height: 42px;
}
.video-frame-top-left img {
  width: 100%;
  height: 100%;
}
.video-frame-top-center {
  flex: 1;
  height: 100%;
}
.video-frame-top-center-top {
  line-height: 24px;
  margin-left: 10px;
  font-size: 15px;
  color: #343434;
}
.video-frame-top-center-bottom {
  line-height: 18px;
  margin-left: 10px;
  font-size: 12px;
  color: #343434;
}
.span-1 {
  color: #999;
  margin-right: 10px;
}
.span-2 {
  color: #32b9ba;
  margin-left: 10px;
}
.video-frame-top-right {
  font-size: 18px;
  color: #32b9ba;
  background: rgb(228, 243, 243);
  border-radius: 15px;
  width: 75px;
  height: 30px;
  text-align: center;
  line-height: 30px;
  margin: auto 0;
}
.video-frame-center {
  width: 100%;
}
.video-frame-center-top {
  font-size: 18px;
  color: #333;
  line-height: 42px;
}
.video-frame-center-bottom {
  width: 343px;
  height: 193px;
}
.video-frame-center-bottom img {
  width: 100%;
  height: 100%;
}
.video-frame-bottom {
  width: 100%;
  height: 40px;
  display: flex;
  justify-content: space-between;
}
.video-frame-bottom-left {
  flex: 1;
  height: 40px;
  margin: auto 0;
}
.span_1 img {
  width: 19px;
  height: 15px;
  margin-right: 8px;
  margin-bottom: -2px;
}
.span_2 {
  font-size: 12px;
  color: #999999;
  margin-right: 21px;
}
.video-frame-bottom-right {
  color: #878a8f;
  font-size: 16px;
  font-weight: 900;
  line-height: 40px;
}
</style>
